app.directive("moveDirective", function() {
    return {
        restrict: "EACM",
        
        templaterUrl: "/views/directives/move.html",
        link: function(scope, element, attr) {}
    }
})
app.directive("navDirective", function($timeout, $interval) {
    return {
        restrict: "EA",
       
        templateUrl: "/views/directives/navDirective.html",
        scope: {
            data: "="
        },
        link: function(scope, element, attr) {
            var timer = $interval(function() {
                if (element[0].querySelectorAll(".navItem").length) {
                    $interval.cancel(timer);
                    angular.forEach(document.querySelectorAll(".secondNav"), function(data) {
                        if (!angular.element(data).children().length) {
                            angular.element(data).parent().bind("mouseover", function() {
                                angular.element(this).css({ "border-color": "transparent" });
                            })
                        }
                    })
                    angular.element(element).find("li").bind("mouseenter", function() {
                        angular.element(this.querySelector(".secondNav")).removeClass("hidden");
                    })
                    angular.element(element).find("li").bind("mouseleave", function() {
                        angular.element(this.querySelector(".secondNav")).addClass("hidden");
                    })
                }
            }, 10)
            scope.show = false;
            scope.schoolSelect = function() {
                scope.show = !scope.show
            }
        }
    }
})
app.directive("footerDirective", function() {
    return {
        restrict: "EA",
     
        templateUrl: "/views/directives/footerDirective.html",
        link: function() {

        }
    }
})
app.directive("carouselDiretive", function($interval, $timeout) {
    return {
        restrict: "EA",
      
        scope: {
            data: "=",
            demo: "@"
        },
        templateUrl: "/views/directives/carouselDirective.html",
        link: function(scope, element, attr) {
            scope.arrowShow = scope.$eval(attr.arrow);
            scope.type = attr.type;
            scope.timer1 = $interval(function() {
                scope.el = $(element).find(".carouselItem");

                if (scope.el.length) {
                    $interval.cancel(scope.timer1);
                    //js控制外层ul的宽度
                    scope.itemWidth = scope.el.css("width");
                    element.find("ul").css({ "width": parseInt(scope.el.length) * parseInt(scope.itemWidth) + "px" });
                    // console.log(scope.el.css("width"));
                    //自动动画
                    scope.initialLeft = $(element.find("ul")).offset().left;
                    scope.moveDistance = 0;
                    scope.move = function() {
                        scope.moveDistance--;
                        $(element.find("ul")).offset({ "left": scope.initialLeft + scope.moveDistance });
                        if (Math.abs(scope.moveDistance) >= parseInt(scope.itemWidth)) {
                            scope.shift = scope.data.shift();
                            scope.data.push(scope.shift);
                            scope.moveDistance = 0;
                            $(element.find("ul")).offset({ "left": scope.initialLeft + scope.moveDistance });
                        }

                    }
                    if (scope.$eval(attr.animate)) {
                        scope.timer2 = $interval(scope.move, 50)
                    }
                }
            }, 10)
            scope.click = function(i) {
                //i=-1,向左移动
                //i=1,向右移动
                //停止动画定时器
                $interval.cancel(scope.timer2);
                if (i == -1) {
                    scope.pop = scope.data.pop();
                    scope.data.unshift(scope.pop);
                } else {
                    scope.shift = scope.data.shift();
                    scope.data.push(scope.shift);

                }
                $(element.find("ul")).offset({ "left": scope.initialLeft });
            }


        }
    }
})
app.directive("breadcrumbDirective", function($state) {
    return {
        restrict: "EA",
        scope: {
            data: "="
        },
        templateUrl: "/views/directives/breadcrumb.html",
        link: function(scope, element, attr) {
            console.log("breadcrumb");
            scope.paramId = $state.params.paramId;
            scope.$watch('Data', function(data) {
                if (data) {
                    angular.forEach(scope.Data.menus, function(data) {
                        if (data.id == scope.paramId) {
                            scope.name = data.name;
                            console.log("yes");
                            if (data.upId) {
                                console.log(data.upId);
                                angular.forEach(scope.Data.menus, function(item) {
                                    if (data.upId == item.id) {
                                        scope.upname = item.name;
                                    }
                                })
                            }
                        }
                    })
                }
            })
        }
    }
})
app.directive("leftNavDirective", function() {
    return {
        restrict: "EA",
        scope: {
            data: "=",
            title: "@",
            params: "="
        },
        templateUrl: "/views/directives/leftNav.html",
        link: function(scope, element, attr) {
            console.log(scope.data);
            console.log(scope.params)
        }
    }
})
app.directive("bannerDirective", function($timeout, $interval) {
    return {
        restrict: "EA",
        scope: {
            data: "="
        },
        templateUrl: "/views/directives/bannerDirective.html",
        link: function(scope, element, attr) {
            var timer = null;
            scope.$watch('data', function(data) {
                if (data && data.length > 1) {
                    $timeout(function() {
                        scope.num = 0;
                        scope.a = $(element[0].querySelectorAll(".bannerDirective"));
                        scope.dWidth =$(element[0].querySelectorAll(".bannerDirective")).width();
                        console.log(scope.a);
                        $(element[0].querySelectorAll(".bannerContainer li")).width(scope.dWidth);
                        $(element[0].querySelectorAll(".bannerContainer ul")).width(scope.dWidth * scope.data.length);
                        scope.i = -1;
                        timer = $interval(function() {
                            scope.num += scope.i;
                            //console.log(scope.num);
                            if (Math.abs(scope.num) >= scope.data.length) {
                                scope.num = 0;
                                $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: 0 });
                            } else {
                                $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: scope.num * scope.dWidth });
                            }
                        }, 5000)
                    }, 0)
                }
            })
            scope.arrow = function(i) {
                $interval.cancel(timer);
                scope.num += i;
                console.log($(".bannerContainer ul").offset().left)
                if (i > 0 && $(element[0].querySelectorAll(".bannerContainer ul")).offset().left >= 0) {
                    scope.num = 0;
                    $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: 0 });
                } else {
                    $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: scope.num * scope.dWidth });
                    if (Math.abs(scope.num) >= scope.data.length) {
                        scope.num = 0;
                        $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: 0 });
                    }
                }
                timer = $interval(function() {
                    scope.num += scope.i;
                    $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: scope.num * scope.dWidth });

                    if (Math.abs(scope.num) >= scope.data.length) {
                        scope.num = 0;
                        $(element[0].querySelectorAll(".bannerContainer ul")).offset({ left: 0 });
                    }
                }, 5000)
            }
        }
    }
})
app.directive("lunbo", function($interval) {
    return {
        restrict: "EA",
        scope: {
            data: "="
        },
        templateUrl: "/views/directives/move.html",
        link: function(scope, element, attr) {
            scope.num = 0;
            scope.timer = $interval(function() {
                scope.num++;
                style();
            }, 5000)
            scope.changeStyle = function(i) {
                $interval.cancel(scope.timer);
                scope.num += i;
                console.log(i + " " + scope.num)
                style();
            }

            function style() {
                if (scope.num == -5) {
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    scope.num = 0;
                }
                if (scope.num == -4) {
                    // $(element).find("li").eq(1).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(2).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(4).css({ "width": "400px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == -3) {
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(4).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == -2) {
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == -1) {
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(1).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == 1) {
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(2).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == 2) {
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == 3) {
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(4).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == 4) {
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(1).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(1).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                }
                if (scope.num == 5) {
                    // $(element).find("li").eq(4).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })
                    // $(element).find("li").eq(0).css({ "width": "600px", "z-index": "10", "left": "0", "top": "57px" })
                    // $(element).find("li").eq(1).css({ "width": "800px", "z-index": "100", "left": "100px", "top": "0" })
                    // $(element).find("li").eq(2).css({ "width": "600px", "z-index": "10", "left": "400px", "top": "57px" })
                    // $(element).find("li").eq(3).css({ "width": "600px", "z-index": "5", "left": "100px", "top": "57px" })

                    $(element).find("li").eq(4).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    $(element).find("li").eq(0).css({ "width": "400px", "z-index": "10", "left": "0", "top": "57px" })
                    $(element).find("li").eq(1).css({ "width": "600px", "z-index": "100", "left": "200px", "top": "0" })
                    $(element).find("li").eq(2).css({ "width": "400px", "z-index": "10", "left": "600px", "top": "57px" })
                    $(element).find("li").eq(3).css({ "width": "400px", "z-index": "5", "left": "100px", "top": "57px" })
                    scope.num = 0;
                }
            }

        }

    }

})
app.directive("employListDirective", function() {
    return {
        restrict: "EA",
        scope: {
            data: "="
        },
        templateUrl: "/views/directives/employListDirective.html",
        link: function(scope, element, attr) {
            scope.show = false;
            scope.showDetail = function() {
                scope.show = !scope.show;
            }
        }
    }
})
app.directive("slideDirective", function($interval, $timeout) {
    return {
        restrict: "EA",
        scope: {
            data: "="
        },
        templateUrl: "/views/directives/3d.html",
        link: function(scope, element, attr) {

            console.log(scope.data);
            scope.show = false;
            scope.timer1 = $interval(function() {

                if ($(element).find(".list li ").length) {
                    $interval.cancel(scope.timer1);
                    scope.list = $(element).find(".list")
                    scope.ul = $(element).find(".list ul");
                    scope.li = $(element).find(".list ul li")
                    scope.ul.width(200 * scope.li.length);
                    scope.num = 0;
                    scope.index = 0;
                    scope.i = 0;
                    scope.index = 0;
                    scope.ul.css({ "left": 0 + "px" });
                    scope.change = function(i) {
                        // scope.ul.css({"transition":"left 1s"});
                        scope.show = true;
                        console.log(parseInt(scope.ul.css("left")));

                        if (i > 0 && parseInt(scope.ul.css("left")) >= 0) {
                            scope.ul.css({ "left": 0 + "px" });
                            return;
                        }
                        if (i < 0 && scope.ul.width() + parseFloat(scope.ul.css("left")) <= 800) {
                            return;
                        } else {

                            scope.num += i;

                            scope.ul.css({ "left": 200 * scope.num + "px" });
                        }
                    }
                    scope.showImg = function($index) {
                        console.log(1111);
                        scope.show = true;
                        console.log($index);
                        scope.index = $index;
                    }
                }
            }, 10)
        }
    }
})
app.directive("bannerShowDirective", function($timeout) {
    return {
        restrict: "EA",
        templateUrl: "/views/directives/bannerShowDirective.html",
        scope: {
            data: "="
        },
        link: function(scope, element, attr) {
            console.log(scope.data)
            scope.$watch('data', function(data) {
                if (data) {
                    $timeout(function() {
                        scope.li = $(".bannerShowDirective li");
                        scope.ul = $(".bannerShowDirective ul");
                        console.log(scope.li.css("width"));
                        scope.index = 0;
                        scope.ulLeft = parseInt(scope.ul.offset().left);
                        console.log(scope.ulLeft);
                        // scope.ul.width(parseInt(scope.li.width())*data.datas.length);
                        scope.ul.css({ "width": parseInt(scope.li.css("width")) * data.datas.length + "px" })
                    }, 0)
                }
            })
            scope.schoolSelect = function(i) {
                scope.index = i;
                if (i >= 3) {
                    scope.ul.offset({ left: scope.ulLeft - 230 * (i - 3) });
                    if (i > scope.data.datas.length - 2) {
                        scope.ul.offset({ left: scope.ulLeft - 230 * (scope.data.datas.length - 5) })
                    }
                    if (parseInt(scope.ul.offset()).left > scope.ulLeft) {
                        scope.ul.offset({ left: scope.ulLeft })
                    }
                    // if( parseInt(scope.ul.offset()).left<=(scoep.data.datas.length-5)*(-230)){

                    // }
                }
            }
            scope.arrow = function(i) {


                scope.currLeft = parseInt(scope.ul.offset().left);
                console.log(scope.currLeft);

                scope.ul.offset({ left: scope.currLeft + i * 230 })
                if (i > 0 && scope.currLeft >= scope.ulLeft) {
                    // scope.enable1=true;
                    // scope.enable2=false;
                    scope.ul.offset({ left: scope.currLeft });
                    if (scope.index <= 4 && scope.index > 0) {
                        scope.index -= i;
                    }
                    return;
                }
                if (i < 0 && scope.index >= scope.data.datas.length - 2) {
                    // scope.enable2=true; 
                    // scope.enable1=false;
                    scope.ul.offset({ left: scope.ulLeft - 230 * (scope.data.datas.length - 5) });
                    scope.index -= i;
                    if (scope.index >= scope.data.datas.length - 1) {
                        scope.index = scope.data.datas.length - 1
                    }
                    return;
                }
                if (i < 0 && scope.index >= scope.data.datas.length - 5) {
                    scope.ul.offset({ left: scope.ulLeft - 230 * (scope.data.datas.length - 5) });
                }
                console.log(111);
                scope.enable2 = false;
                scope.enable1 = false;
                scope.index -= i;
                console.log(scope.index);
            }
        }

    }
})